package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabReqResult;
import com.ysd.lis.entity.lab.LabRptGroup;
import com.ysd.lis.mapper.lab.LabReqResultMapper;
import com.ysd.lis.service.lab.LabReqResultService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Bai
 * @since 2023-12-26
 */
@Service
public class LabReqResultServiceImpl extends ServiceImpl<LabReqResultMapper, LabReqResult> implements LabReqResultService {
    @Autowired
    LabReqResultMapper labReqResultMapper;
    @Override
    public Result getReqResultList(String reqNo) {
        if (StringUtils.isEmpty(reqNo)) {
            return Result.succ(1, "申请编号为空", "");
        }
        MPJLambdaWrapper<LabReqResult> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LabReqResult.class);
        queryWrapper.selectAs("rg",LabRptGroup::getRptGroupName,LabReqResult::getRptGroupName);
        queryWrapper.leftJoin(LabRptGroup.class, "rg", p -> p.eq(LabRptGroup::getRptGroup, LabReqResult::getRptGroup).eq(LabRptGroup::getDelFlag, 0));

        queryWrapper.eq(LabReqResult::getDelFlag, 0);
        if (!StringUtils.isEmpty(reqNo)) {
            queryWrapper.eq(LabReqResult::getReqNo, reqNo);
        }
        queryWrapper.orderByAsc(LabReqResult::getRptGroup);
        queryWrapper.orderByAsc(LabReqResult::getFeeCode);

        List<LabReqResult> labReqRsultList = labReqResultMapper.selectList(queryWrapper);
        return Result.succ(1, "查询成功!", labReqRsultList);
    }
}
